package com.thirteen.app.controller;

import com.thirteen.app.entity.Answer;
import com.thirteen.app.entity.Question;
import com.thirteen.app.service.QuestionService;
import com.thirteen.app.utils.tools.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.oas.annotations.EnableOpenApi;

import javax.annotation.Resource;
import java.util.List;

/**
 * 题目(Question)表控制层
 *
 * @author 郑清林
 * @since 2021-09-06 10:29:43
 */

@CrossOrigin
@Api(tags = "题目管理模块")
@EnableOpenApi
@RestController
@RequestMapping("/api/student/question")
public class QuestionController {
    /**
     * 服务对象
     */
    @Resource
    private QuestionService questionService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("查询一个")
    @GetMapping("selectOne")
    public Question selectOne(Integer id) {
        return this.questionService.queryById(id);
    }

    @ApiOperation("更改题目信息")
    @PostMapping("update")
    public CommonResult update(@RequestBody Question question) {
        questionService.update(question);
        return CommonResult.success(question);
    }


    @ApiOperation("删除题目")
    @PostMapping("deleteQu")
    public CommonResult deleteQuestion(Integer questionId, Integer repositoryId) {
        return CommonResult.success(questionService.deleteQuestion(questionId, repositoryId));
    }


    @ApiOperation("插入一条题目信息,并且插入对应的答案列表")
    @PostMapping("createQu")
    public CommonResult insert(@RequestBody Question question, @RequestBody List<Answer> answers) {

        return CommonResult.success(questionService.insert(question, answers));
    }
//
//    @ApiOperation("根据题目查询答案")
//    @GetMapping("selectQu")
//    public CommonResult getquestionPageList(Integer currentPage,
//                                            Integer pageSize,
//                                            Integer questionType,
//                                            Integer repositoryId,
//                                            Integer id) {
//        Map<String, Object> map = questionService.getquestionPageList(1, 10, questionType, repositoryId, id);
//        return CommonResult.success(map);
//    }

    @PostMapping("getQuestionList")
    @ApiOperation("获取题目列表")
    public CommonResult getQuestionList(Integer id, Integer mode, Integer[] types, Integer userId) {
        return CommonResult.success(questionService.getQuestionList(id, mode, types, userId));
    }

    @PostMapping("deleteWrongQu")
    @ApiOperation("删除错题")
    public CommonResult deleteWrongQu(Integer questionId, Integer examId) {
        return CommonResult.success(questionService.deleteWrongQu(questionId, examId));
    }


}
